package com.shujia.Day07;

import java.util.Scanner;

public class Demo07StringBuffer {
    public static void main(String[] args) {
        /*
            TODO StringBuffer 使用
                添加功能
                    public StringBuffer append(String str)
                    public StringBuffer insert(int offset,String str)
                删除功能
                    public StringBuffer deleteCharAt(int index)
                    public StringBuffer delete(int start,int end)
                替换功能
                    public StringBuffer replace(int start,int end,String str)  // 将指定的下标区间数据替换成 给定字符串
                反转功能
                    public StringBuffer reverse()
                截取功能
                    public String substring(int start)
                    public String substring(int start,int end)
                    // return new String(value, start, end - start); 和 String类型中的 substring一样
                StringBuilder:
                    具有和StringBuffer相同的API功能，但是StringBuilder速度更快，但是线程不安全
                    StringBuffer 线程安全的但是 速度不快
                String,StringBuffer,StringBuilder的区别  => 面试常问
                StringBuffer 和 数组 的区别
                    StringBuffer 底层是一个动态数组 随着存储数据量的增加，其数组的长度也会不断增加
                    对于数组来说，长度一旦定义，不可发生更改

         */
//        StringBuffer str = "";
        StringBuffer str =  new StringBuffer();
        str.append("a");
        str.append("b");
        System.out.println(str);

        str.insert(1,"hello");
        System.out.println(str);

        str.delete(1,6);
        System.out.println(str);

        str.deleteCharAt(1);
        System.out.println(str);

        // TODO 在构造对象时，传入一个初识的String字符串数据
        StringBuffer stringBuffer = new StringBuffer("oaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun");
        stringBuffer.replace(0,stringBuffer.length(),"java");
        System.out.println(stringBuffer);
        stringBuffer = new StringBuffer(stringBuffer.toString().replace("java","$"));
        System.out.println(stringBuffer);

        StringBuffer buffer = new StringBuffer("2345");
        System.out.println(buffer.substring(1, 3));
        System.out.println(buffer);


        Scanner scanner = new Scanner(System.in);
        System.out.println("输入一个字符串");
        StringBuffer stringBf = new StringBuffer(scanner.next());
        System.out.println(stringBf.reverse());
        StringBuffer stringBuffer1 = new StringBuffer();
        stringBuffer1.append("oaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun");


        StringBuilder stringBuilder = new StringBuilder();

    }
}
